package stream;

import cn.hutool.core.collection.CollUtil;
import cn.hutool.core.comparator.CompareUtil;

import java.util.List;

public class ReduceTest {
    public static void main(String[] args) {
        List<Student> studentList = CollUtil.toList(new Student().setId(1).setAge(10), new Student().setId(2).setAge(9), new Student().setId(3).setAge(11));

        // 求出age最大的
        studentList.stream().reduce((student1, student2) -> CompareUtil.compare(student1.getAge(), student2.getAge()) > 0 ? student1 : student2).get();
        // 学生总数
        studentList.stream().map(student -> 1).reduce(0, (student1, student2) -> student1 + student2);
    }
}
